//David Wasser
//February 18, 2009
//Software Design, Period 6
//Ultimate Frisbee

/* Strategy is the abstract class which is the super class for all the strategies.
 * The strategies control all of the MovementRoutines to move Players to the correct
 * positions.
 */
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import javax.vecmath.Point3d;
public abstract class Strategy{
	int[][] locs;
	short force; // 0 means no force, 1 means force up, 2 means force down
	Map<Integer, MovementRoutine> routes;
	Team team;
	Field field;
	boolean starting = false;
	
	/** DiscChange is called when the Disc is either caught or thrown and the input
	 ** Player is the one that threw it or caught it.
	 **/
	public void discChange(Player player){
	}//End discChange()
	
	//Returns the player in players who would have to travel the least distance to reach the disc and the point where that player would intercept the disc, in the form {player, point}.
	public static Object[] getClosestToDisc(Disc disc, Set<Player> players, double deltaT)
	{
		ArrayList<Point3d> discPos = ((DiscMechanics) disc.routine).positionStepsArray(deltaT);
		Player closest = null;
		Point3d contactPoint = null;
		
		Iterator<Point3d> positr = discPos.iterator();
		Point3d pos = null;
		if(positr.hasNext())
			pos = positr.next();
		for(int i = 0; positr.hasNext() && closest != null; i++, pos = positr.next())
		{
			for(Player player : players)
				if(pos.z <= player.height && Math.hypot(pos.x - player.position.x, pos.y - player.position.y) < player.speed * deltaT * i && closest != null && Math.hypot(pos.x - player.position.x, pos.y - player.position.y) < Math.hypot(pos.x - closest.position.x, pos.y - closest.position.y))
				{
					closest = player;
					contactPoint = pos;
				}
		}
		
		Object[] result = {closest, contactPoint};
		return result;
	}//End getClosestToDisc(Disc, Set<Player>)
	
	/** Sets the field of the Strategy and all of its Movement Routines
	 ** to the input Field.
	 **/
	public void setField(Field gameField){
		field = gameField;
		routes.isEmpty();
		Iterator<Integer> it = routes.keySet().iterator();
		while(it.hasNext())
			routes.get(it.next()).setField(gameField);
	}//End setField()
}//End Strategy